package cn.tedu.egarticle.base.exception;

import cn.tedu.egarticle.base.response.JsonResult;
import cn.tedu.egarticle.base.response.StatusCode;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
        String data = e.getFieldError().getDefaultMessage();
        return new JsonResult(StatusCode.VALIDATED_ERROR, data);
    }
}
